<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Db;

/**
 * 测试接口
 */
class Test extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = '*';

    public function _initialize()
    {
        parent::_initialize();
    }

    /**
     * 测试接口
     */
    public function index()
    {
        $this->success('测试成功', [
            'isLogin' => $this->auth->isLogin(),
            'token' => $this->auth->getToken(),
            'user' => $this->auth->isLogin() ? $this->auth->getUserinfo() : null
        ]);
    }

    /**
     * 需要认证的测试接口
     */
    public function auth()
    {
        if (!$this->auth->isLogin()) {
            $this->error('未登录', null, 401);
        }

        $this->success('认证成功', [
            'user' => $this->auth->getUserinfo()
        ]);
    }
}